package com.fenghuajueli.lib_pictureselect.utils;

import android.graphics.Bitmap;
import android.util.LruCache;

public class VideoCoverCacheUtils {

    private LruCache<String, Bitmap> mLruCache;
    private static VideoCoverCacheUtils instance;

    private VideoCoverCacheUtils() {
        long overMemory = Runtime.getRuntime().maxMemory();
        int myMemory = (int) (overMemory / 8);
        mLruCache = new LruCache<String, Bitmap>(myMemory) {
            @Override
            protected int sizeOf(String key, Bitmap value) {
                return value.getRowBytes() * value.getHeight();
            }
        };
    }


    public static VideoCoverCacheUtils getInstance() {
        if (instance == null) {
            synchronized (VideoCoverCacheUtils.class) {
                if (instance == null) {
                    instance = new VideoCoverCacheUtils();
                }
            }
        }
        return instance;
    }


    public void setBitmap(String key, Bitmap bitmap) {
        mLruCache.put(key, bitmap);
    }

    //get
    public Bitmap getBitmap(String key) {
        return mLruCache.get(key);
    }


}
